#include <QJsonObject>
#include <QJsonArray>

#include <gp_Pln.hxx>

#include "Plane.h"
#include "OcctOsg.h"
#include "OsgUtil.h"

Plane::Plane()
{}

gp_Pln Plane::getPln() const
{
	gp_Dir zDir = toDir(m_zAxis);
	gp_Dir xDir = toDir(m_xAxis);
	gp_Pnt pt = toPnt(m_origin);
	return gp_Pln(gp_Ax3(pt, zDir, xDir));
}

void Plane::save(QJsonObject & json) const
{
	json["origin"] = saveVec3d(m_origin);
	json["xAxis"] = saveVec3d(m_xAxis);
	json["yAxis"] = saveVec3d(m_yAxis);
}

void Plane::load(const QJsonObject & json)
{
	m_origin = loadVec3d(json["origin"].toArray());
	m_xAxis = loadVec3d(json["xAxis"].toArray());
	m_yAxis = loadVec3d(json["yAxis"].toArray());
	m_zAxis = m_xAxis ^ m_yAxis;
}
